﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        执行任务-Step1:输入参数
    </title>
    <meta name="description" content="">
    <meta name="author" content="">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <!-- #CSS Links -->
    <!-- Basic Styles -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="css/font-awesome.css">

    <!-- SmartAdmin Styles : Caution! DO NOT change the order -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-production-plugins.css">
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-production.css">
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-skins.css">

    <!-- SmartAdmin RTL Support -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-rtl.css">

    <!-- Demo purpose only: goes with demo.js, you can delete this css when designing your own WebApp -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/demo.css">

    <!-- #FAVICONS -->
    <link rel="shortcut icon" href="img/favicon/favicon.ico" type="image/x-icon">
    <link rel="icon" href="img/favicon/favicon.ico" type="image/x-icon">

    <!-- #GOOGLE FONT -->
    <link rel="stylesheet" href="css/open-sans.css" type="text/css">

    <!-- #APP SCREEN / ICONS -->
    <link rel="apple-touch-icon" href="img/splash/sptouch-icon-iphone.png">
    <link rel="apple-touch-icon" sizes="76x76" href="img/splash/touch-icon-ipad.png">
    <link rel="apple-touch-icon" sizes="120x120" href="img/splash/touch-icon-iphone-retina.png">
    <link rel="apple-touch-icon" sizes="152x152" href="img/splash/touch-icon-ipad-retina.png">

    <!-- iOS web-app metas : hides Safari UI Components and Changes Status Bar Appearance -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <!-- Startup image for web apps -->
    <link rel="apple-touch-startup-image" href="img/splash/ipad-landscape.png"
          media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)">
    <link rel="apple-touch-startup-image" href="img/splash/ipad-portrait.png"
          media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)">
    <link rel="apple-touch-startup-image" href="img/splash/iphone.png" media="screen and (max-device-width: 320px)">
    <link href="appcss/Common.css" rel="stylesheet" />

</head>
<body class="desktop-detected minified">

    <!-- #MAIN PANEL -->
    <div id="main" role="main">

        <!-- RIBBON -->
        <div id="ribbon">

            <span class="ribbon-button-alignment">
                <span class="btn btn-ribbon"><i class="fa fa-home"></i></span>
            </span>

            <!-- breadcrumb -->
            <ol class="breadcrumb">
                <li><a href="SchedulingTaskManagement.html">调度任务管理</a></li>
                <li>执行任务-Step1:输入参数</li>
            </ol>
            <!-- end breadcrumb -->

        </div>
        <!-- END RIBBON -->
        <!-- MAIN CONTENT -->
        <div id="content">
            <div class="row hidden">
                <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
                    <h1 class="page-title txt-color-blueDark">
                        <i class="fa fa-edit fa-fw "></i>
                        主页
                        <span>
                            >
                            执行任务-Step1:输入参数
                        </span>
                    </h1>
                </div>

            </div>

            <!-- widget grid -->
            <section id="widget-grid" class="">

                <!-- row -->
                <div class="row">

                    <!-- NEW WIDGET START -->
                    <!-- NEW WIDGET START -->
                    <article class="col-sm-12 col-md-12 ">

                        <!-- Widget ID (each widget will need unique ID)-->
                        <div class="jarviswidget" id="wid-id-2" data-widget-colorbutton="false"
                             data-widget-editbutton="false">
                            <header>
                                <h2>执行任务-Step1:输入参数</h2>

                            </header>

                            <!-- widget div-->
                            <div>

                                <!-- widget edit box -->
                                <div class="jarviswidget-editbox">
                                    <!-- This area used as dropdown edit box -->

                                </div>
                                <!-- end widget edit box -->
                                <!-- widget content -->
                                <div class="widget-body no-padding">

                                    <!-- Success states for elements -->

                                    <form action="#" class="smart-form" id="ManualExecuteTask">
                                        <header>填写相关信息</header>
                                        <fieldset>
                                            <section>
                                                <label class="label">任务</label>
                                                <label class="input">
                                                    <input type="text" id="TaskName" disabled="disabled" />
                                                </label>
                                            </section>
                                            <section>
                                                <label class="label">服务</label>
                                                <label class="input">
                                                    <input type="text" id="ServiceName" disabled="disabled" />
                                                </label>
                                            </section>
                                            <section>
                                                <label class="label">服务类型</label>
                                                <label class="input">
                                                    <input type="text" id="ServiceType" disabled="disabled" />
                                                </label>
                                            </section>
                                            <section>
                                                <label class="label">数据源</label>
                                                <label class="input">
                                                    <input type="text" id="SourceName" disabled="disabled" />
                                                </label>
                                            </section>
                                            <section>
                                                <label class="label">数据表</label>
                                                <label class="input">
                                                    <input type="text" id="TableName" disabled="disabled" />
                                                </label>
                                            </section>


                                        </fieldset>
                                        <fieldset>
                                            <section>
                                                <label class="label">参数列表</label>
                                                <table class="table table-bordered"
                                                       style="width: 80% !important; float: left; margin-right: 2%;" id="table-details">
                                                    <thead>
                                                        <tr>
                                                            <th>名称</th>
                                                            <th>类型</th>
                                                            <th>值</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody></tbody>
                                                </table>
                                            </section>
                                        </fieldset>
                                        <footer>
                                            <button type="button" onclick="window.location.reload()" class="btn btn-primary">刷新</button>
                                            <button type="submit" id="action_btn" class="btn btn-primary">执行</button>
                                        </footer>
                                    </form>
                                    <!--/ Success states for elements -->
                                </div>
                                <!-- end widget content -->
                            </div>
                            <!-- end widget div -->
                        </div>
                        <!-- end widget -->
                    </article>
                </div>

                <!-- end row -->

            </section>
        </div>
        <!-- END MAIN CONTENT -->
    </div>


    <!--================================================== -->
    <!-- PACE LOADER - turn this on if you want ajax loading to show (caution: uses lots of memory on iDevices)
    <script data-pace-options='{ "restartOnRequestAfter": true }' src="js/plugin/pace/pace.min.js"></script>-->
    <!-- #PLUGINS -->
    <!-- Link to Google CDN's jQuery + jQueryUI; fall back to local -->


    <script src="js/libs/jquery-2.1.1.min.js"></script>
    <script src="js/libs/jquery-ui-1.10.3.min.js"></script>
    <!-- BOOTSTRAP JS -->
    <script src="js/bootstrap/bootstrap.min.js"></script>

    <!-- IMPORTANT: APP CONFIG -->
    <script src="js/app.config.js"></script>


    <!-- CUSTOM NOTIFICATION -->
    <script src="js/notification/SmartNotification.min.js"></script>

    <!-- JARVIS WIDGETS -->
    <script src="js/smartwidgets/jarvis.widget.min.js"></script>


    <!-- SPARKLINES -->
    <script src="js/plugin/sparkline/jquery.sparkline.min.js"></script>

    <!-- JQUERY MASKED INPUT -->
    <script src="js/plugin/masked-input/jquery.maskedinput.min.js"></script>


    <!-- JQUERY UI + Bootstrap Slider -->
    <script src="js/plugin/bootstrap-slider/bootstrap-slider.min.js"></script>

    <script src="js/app.min.js"></script>
    <script src="appjs/Common.js"></script>
    <script src="appjs/Helper.js"></script>
    <script src="js/plugin/jquery-upload/jquery-upload.js"></script>
    <script src="js/plugin/My97DatePicker/WdatePicker.js"></script>


    <script src="js/plugin/jquery-validate/jquery.validate.min.js"></script>
    <script src="js/plugin/jquery-validate/jquery.metadata.js"></script>
    <script src="js/plugin/jquery-validate/messages_cn.js"></script>
    <script>
        var taskId = GetQueryString("taskId");
        var ServiceTypelist = GetDataServiceTypeList();
        var EnableDataVerification = true;
        $(function () {
            $("#TaskId").val(taskId);
            $("#action_btn").html("执行");
            $("#action_btn").removeAttr("disabled");
            var getTaskParameterList = function () {
                $.ajax({
                    url: apiUrl,
                    data: {
                        "sys:sno": "ETL",
                        "sys:act": "GetTaskParameterList",
                        "TaskId": taskId
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.IsSccuess) {
                            ProductionTable(data.Data.Items);
                        } else {
                            if (IsLogined(data.ErrorCode)) {
                                alert(data.Message);
                            }
                        }
                    },
                    beforeSend: function () {
                        // $("btn_login").html("登录中...");
                    }
                });
            }
            var getTaskInfo = function () {
                $.ajax({
                    url: apiUrl,
                    data: {
                        "sys:sno": "Task",
                        "sys:act": "Get",
                        "TaskId": taskId
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.IsSccuess) {
                            $("#SourceName").val(data.Data.DtSourceText);//名称
                            $("#ServiceName").val(data.Data.DtSerText);
                            $("#TableName").val(data.Data.DtTableText);
                            $("#TaskName").val(data.Data.Name);
                            getServiceInfo(data.Data.DtSerId);
                            EnableDataVerification = data.Data.EnableDataVerification;

                        } else {
                            if (IsLogined(data.ErrorCode)) {
                                alert(data.Message);
                            }
                        }
                    },
                    beforeSend: function () {
                        // $("btn_login").html("登录中...");
                    }
                });
            }
            var getServiceInfo = function (id) {
                $.ajax({
                    url: apiUrl,
                    data: {
                        "sys:sno": "ETL",
                        "sys:act": "GetDataService",
                        "DataServiceId": id
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.IsSccuess) {
                            $("#ServiceType").val(getServiceTypeName(data.Data.TypeId));//名称
                        } else {
                            if (IsLogined(data.ErrorCode)) {
                                alert(data.Message);
                            }
                        }
                    },
                    beforeSend: function () {
                        // $("btn_login").html("登录中...");
                    }
                });
            }

            $("#ManualExecuteTask").validate({
                submitHandler: function (form) {
                    var asktitle = "";
                    var haveerror = false;
                    var havefile = false;
                    var filename = "";
                    var uploadstr = "";
                    var trs = $("#table-details tbody tr");
                    var formData = new Object();
                    formData["TaskId"] = taskId;
                    formData["sys:sno"] = "ETL";
                    formData["sys:act"] = "ManualExecuteTask";
                    try {
                        for (var i = 0; i < trs.length; i++) {
                            var tempobj = JSON.parse($(trs[i]).attr("data"));
                            if (tempobj.type == "System.IO.FileInfo") {
                                havefile = true;
                                uploadstr = "tp:" + tempobj.name;
                                filename = "dtcol-value-" + tempobj.editNum;
                            } else {
                                if ($("#dtcol-value-" + tempobj.editNum + '_selectOption').length > 0) {
                                    var selectOption = $("#dtcol-value-" + tempobj.editNum + '_selectOption').val();
                                    var formatOption = $("#dtcol-value-" + tempobj.editNum + '_formatOption').val();
                                    var beginDate = $("#dtcol-value-" + tempobj.editNum + '_beginDate').val();
                                    var endDate = $("#dtcol-value-" + tempobj.editNum + '_endDate').val();
                                    asktitle = ("确定要获取:" + beginDate + " 至 " + endDate + "时间段内的数据？");
                                    if (formatOption === "" || beginDate === "" || endDate === "") {
                                        alert("参数不能为空");
                                        haveerror = true;
                                        return;
                                    } else {
                                        formData["tp:" + tempobj.name] = selectOption + "#" + formatOption + "#" + beginDate + "#" + endDate;
                                    }
                                } else {
                                    formData["tp:" + tempobj.name] = $("#dtcol-value-" + tempobj.editNum).val();
                                }
                            }
                        }
                    } catch (e) {
                        console.log(e);
                    }
                    if (haveerror) {
                        return;
                    }
                    if (asktitle===""||confirm(asktitle)) {
                        ShowGritter("提交中");
                        //alert( $("#action_btn").html());
                        $("#action_btn").html("执行中...");
                        $("#action_btn").attr("disabled", "disabled");
                        if (havefile) {
                            try {
                                $("#" + filename).upload({
                                    // 上传地址
                                    action: apiUrl,
                                    // 文件域名字
                                    name: uploadstr,
                                    // 其他表单数据
                                    data: formData,
                                    // 上传完成后, 返回json, text
                                    // dataType: 'json',
                                    // 上传之后回调
                                    onsuccess: function (data) {
                                        $("#action_btn").html("执行");
                                        $("#action_btn").removeAttr("disabled");
                                        if (data.IsSccuess) {
                                            if (EnableDataVerification) {
                                                ShowGritter("执行成功", 2, "SchedulingTaskManualExecutionTwo.html?taskId=" + taskId);
                                            } else {
                                                ShowGritter("执行成功", 2, "SchedulingTaskManagement_Section.html");
                                            }
                                        } else {
                                            if (IsLogined(data.ErrorCode)) {
                                                alert("失败（" + "错误代码：" + data.ErrorCode + "，错误信息：" + data.Message + ")");
                                            }
                                        }
                                    },
                                    beforeSend: function () {
                                        ShowGritter("提交中");
                                    },
                                    error: function () {
                                        alert("系统异常，请稍后再试");
                                        $("#action_btn").html("执行");
                                        $("#action_btn").removeAttr("disabled");
                                    }
                                });
                            } catch (e) {
                                alert("系统异常，请稍后再试");
                                $("#action_btn").html("执行");
                                $("#action_btn").removeAttr("disabled");
                            }
                        } else {
                            $.ajax({
                                url: apiUrl,
                                data: formData,
                                type: "Post",
                                dataType: "json",
                                success: function (data) {
                                    $("#action_btn").html("执行");
                                    $("#action_btn").removeAttr("disabled");
                                    if (data.IsSccuess) {
                                        if (EnableDataVerification) {
                                            ShowGritter("执行成功", 2, "SchedulingTaskManualExecutionTwo.html?taskId=" + taskId);
                                        } else {
                                            ShowGritter("执行成功", 2, "SchedulingTaskManagement.html");
                                        }
                                    } else {
                                        if (IsLogined(data.ErrorCode)) {
                                            alert("失败（" + "错误代码：" + data.ErrorCode + "，错误信息：" + data.Message + ")");
                                        }
                                    }
                                },
                                error: function () {
                                    alert("系统异常，请稍后再试");
                                    $("#action_btn").html("执行");
                                    $("#action_btn").removeAttr("disabled");
                                }
                            });
                        }

                    }
                }
            });
            getTaskInfo();
            getTaskParameterList();
        });
        var getServiceTypeName = function (typeId) {
            if (ServiceTypelist != null && ServiceTypelist.length != 0) {
                for (var i = 0; i < ServiceTypelist.length; i++) {
                    if (typeId == ServiceTypelist[i].Id) {
                        return ServiceTypelist[i].Caption;
                    }
                }
            }
            return "暂无";
        }
        var ProductionTable = function (data) {

            var trlist = "";
            for (var i = 0; i < data.length; i++) {
                var $this = data[i];
                trlist += AssembleData({ name: $this.Name, type: $this.Type, editNum: i, value: $this.Value });
            }
            $("#table-details").append(trlist);


        }

        //传入data对象返回一行的表格数据
        var AssembleData = function (data) {
            var tr = ("<tr data='" + JSON.stringify(data) + "'><td>");
            tr += (data.name + "</td>");
            tr += ("<td>" + data.type + "</td>");
            if (data.type == "System.IO.FileInfo") {
                tr += ("<td><input type=\"file\" class='required' accept=\"application/msexcel,.xlsx,.xls\"  id=\"dtcol-value-" + data.editNum + "\" /></td></tr>");
            } else if (data.type == "System.DateTime") {
                tr += ("<td><input type='radio' name='Section' onclick='OnSection(this.id)'  id=\"dtcol-value-" + data.editNum + "_radio\"/> <input type=\"text\" class='Wdate valueOption' onclick=\"WdatePicker(({ dateFmt: 'yyyy-MM-dd H:mm:ss' }))\"   name='tp:" + data.name + "'  id=\"dtcol-value-" + data.editNum + "\"value=\"" + data.value + "\"  /><span  class='sectionContainer'></span></td></tr>");
            } else {
                tr += ("<td><input type='radio' name='Section' onclick='OnSection(this.id)'  id=\"dtcol-value-" + data.editNum + "_radio\" /> <input type=\"text\" class='valueOption'  name='tp:" + data.name + "'  id=\"dtcol-value-" + data.editNum + "\" value=\"" + data.value + "\"  /><span class='sectionContainer'></span></td></tr>");
            }
            return tr;
        }

        var OnSection = function (id) {
            id = id.replace("_radio", "");
            $(".valueOption").show();
            $(".sectionContainer").html('');
            var selectOption = " 模式:<select class='selectOption' onchange='OnselectOptionChange(this.id)'  id=\"" + id + "_selectOption\"><option value='0'>日</option><option value='1'>月</option><option value='2'>年</option> </select>  时间:";
            var formatOption = " 格式：<input class='formatOption required' id=\"" + id + "_formatOption\" placeholder='yyyy年，MM月，dd日' />";
            var beginDate = "<input type=\"text\"class='beginDate required' onclick='OnChoiceDate()'  id=\"" + id + "_beginDate\" />至";
            var endDate = "<input type=\"text\" class='endDate required'  onclick='OnChoiceDate()'  id=\"" + id + "_endDate\" />";
            $("#" + id).next().html(selectOption + beginDate + endDate + formatOption);
            $("#" + id).hide();
        }
        var OnChoiceDate = function () {
            var selectOption = parseInt($(".selectOption").val());
            if (selectOption === 0) {
                WdatePicker(({ dateFmt: 'yyyy-MM-dd' }));
            } else if (selectOption === 1) {
                WdatePicker(({ dateFmt: 'yyyy-MM' }));
            } else {
                WdatePicker(({ dateFmt: 'yyyy' }));
            }
        }
        var OnselectOptionChange = function (id) {
            id = id.replace("_selectOption", "");
            $("#" + id + '_formatOption').val("");
            $("#" + id + '_beginDate').val("");
            $("#" + id + '_endDate').val("");
        }
    </script>
</body>
</html>
